import sqlite3


class User:
    """创建用户个人信息"""

    def __init__(self, user_id, user_name, user_password):
        self.id = user_id
        self.username = user_name
        self.password = user_password

    def to_string(self):
        return {"id": self.id, "username": self.username, "password": self.password}


def insert_user(user):
    conn = sqlite3.connect('identifier.sqlite')
    sql = 'insert into user (username, password) values(?, ?)'
    data = [
        (user.username, user.password)
    ]
    with conn:
        conn.executemany(sql, data)


def select_user(username):
    conn = sqlite3.connect('identifier.sqlite')
    with conn:
        results = conn.execute("select * from user where username = " + username)
        for result in results:
            user = User(result[0], result[1], result[2])
            return user


def select_sync_path(user_id):
    conn = sqlite3.connect('identifier.sqlite')
    local_paths = []
    with conn:
        results = conn.execute("select * from sync_path where user_id = " + str(user_id))
        for result in results:
            print(result)
            local_paths.append(result)
        return local_paths


cur_uid = 0


def test():
    global cur_uid
    print(cur_uid)
    cur_uid += 10


if __name__ == '__main__':
    # locale_paths = select_sync_path(1)
    # for locale_path in locale_paths:
    #     print(locale_path[2])
    # print(select_sync_path(1))
    test()
    test()
    test()
